package cn.jji8.QSGUI;


import cn.jji8.QSGUI.Gui.GuiManger;
import cn.jji8.QSGUI.quick.logger.Logger;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.shop.Shop;


public class Listener implements org.bukkit.event.Listener{
    QuickShop QuickShop;
    public Listener(){
        QuickShop = (org.maxgamer.quickshop.QuickShop) org.bukkit.Bukkit.getPluginManager().getPlugin("QuickShop");
    }

    /**
     * 监听点击事件
     * */
    @EventHandler
    public void PlayerInteractEvent(PlayerInteractEvent a){
        Logger.putdebug(a.getPlayer()+"交互方块");
        if(a.getAction().equals(Action.LEFT_CLICK_BLOCK)){
            Logger.putdebug(a.getPlayer()+"是左键");
            Block block = a.getClickedBlock();
            BlockData Drops = block.getBlockData();
            if(Drops instanceof Directional){
                Directional sign = (Directional) Drops;
                BlockFace blockFace =  sign.getFacing();
                Shop EAST = QuickShop.getShopManager().getShop(block.getRelative(blockFace,-1).getLocation());
                Logger.putdebug(block.getRelative(blockFace,-1).getLocation().toString());
                Shop shop = null;
                if(EAST!=null){
                    shop = EAST;
                }
                if(shop!=null){
                    Logger.putdebug(a.getPlayer()+"点击了商店");
                    GuiManger.open(a.getPlayer(),shop);
                }
            }
        }

    }

}
